package beanstao.util.type.base;

import org.apache.commons.lang.StringUtils;

import beanstao.util.Util;
import beanstao.util.reflect.Mirror;
import beanstao.util.type.Castor;

public class String2Number extends Castor<String, Number>
{

	@Override
	public Number cast(String src, Class<?> toType, String... args)
	{
		try
		{
			return (Number) Mirror.me(toType).getWrapperClass().getConstructor(String.class).newInstance(StringUtils.isBlank(src) ? "0" : src);
		}
		catch (Exception e)
		{
			throw Util.wrapThrow(e);
		}
	}

}
